package org.dizena.web;

import com.zaxxer.hikari.HikariDataSource;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.dizena.service.TestService;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
@Slf4j
@RestController
public class TestApi {

    @Resource
    private JdbcTemplate jdbcTemplate;
    @Resource(name = "jdbcTemplate2")
    private JdbcTemplate jdbcTemplate2;
    @Resource
    private TestService testService;
    @Resource
    private DataSource dataSource;

    @GetMapping("/1")
    public String test1() {
        Integer i1 = jdbcTemplate.queryForObject("select count(1) cnt from t_test", (rs, i) -> rs.getInt(1));
        log.info("i1="+i1);
        Integer i2 = jdbcTemplate2.queryForObject("select count(1) cnt from t_account", (rs, i) -> rs.getInt(1));
        log.info("i2="+i2);
        testService.count();
        testService.testSelect();
        if(dataSource instanceof HikariDataSource){
            HikariDataSource dss = (HikariDataSource)dataSource;
            log.info("------------------>"+dss.getHikariConfigMXBean().getMaximumPoolSize());
        }
        return "1";
    }
}
